class Solution {
    public int countBinarySubstrings(String s) {
        int pro=0;
        int n=s.length();
        int result=0;
        int xiao=0;
        int last=0;
        while(pro<n){
            int count=0;
            char c=s.charAt(pro);
            while(pro<n&&s.charAt(pro)==c){
                count++;
                pro++;
            }
            result+=Math.min(count,xiao);
            xiao=count;
        }
        return result;
    }
}
